package com.kaisu.blog.domain.user.vo;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author kaisu
 */
public record Password(String encryptedPassword) {
    private final static PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    public static Password create(String plainPassword) {
        return new Password(passwordEncoder.encode(plainPassword));
    }

    public boolean matches(String plainPassword) {
        return passwordEncoder.matches(plainPassword, this.encryptedPassword);
    }
}



